/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: agent-java
 * Description: Agent written in java language
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */
package ru.ffind.agent.dao;

import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import ru.ffind.agent.db.DbDirectory;
import ru.ffind.agent.db.DbHost;
import ru.ffind.common.model.Filename;

/**
 * Arguments utilities.
 *
 * @author Rage Steel
 */
public final class ArgUtils {

    private ArgUtils() {
        // Private constuctor to disallow creating of instance
    }

	@SuppressWarnings("unchecked")
	public static Map<String, Object>[] toBatchArgs(List<Map<String, Object>> args) {
		return args.toArray(new Map[0]);
	}

	/**
	 * Create arguments map with host_id.
     *
     * @param host
	 * @return
	 */
	public static Map<String, Object> createHostArgs(DbHost host) {
		return Maps.newHashMap(Collections.singletonMap("host_id",
                (Object)host.getHostId()));
	}

	/**
	 * Create arguments map with host_id and dir_id.
     *
	 * @param dir
	 * @return
	 */
	public static Map<String, Object> createDirArgs(DbDirectory dir) {
		Map<String, Object> args = Maps.newHashMap();
        args.put("host_id", dir.getHostId());
		args.put("dir_id", dir.getDirId());
		return args;
	}

    /**
     * Create arguments for file
     *
     * @param parentDir
     * @param base
     * @return
     */
	public static Map<String, Object> createFilenameArgs(DbDirectory parentDir,
            Filename base, Date appDate) {
		Map<String, Object> args = createDirArgs(parentDir);
		args.put("file_name", base.getName());
		args.put("file_flags", 0);
		args.put("file_size", base.getFileSize());
		args.put("file_datetime", base.getDatetime());
		args.put("app_date", appDate);
		return args;
	}

}
